package com.gem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gem.entity.Product;
import com.gem.mapper.ProductMapper;
import com.gem.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.gem.util.PageUtil.PAGESIZE;

/**
 * @author 刘聪
 * Created  on 2021/3/21
 */
@Service
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public List<Product> findByCategoryId(Integer categoryId) {
        Map<String, Object> map = new HashMap<>();
        map.put("category_id", categoryId);
        return productMapper.selectByMap(map);
    }

    @Override
    public Page selectAll(Integer pageNum) {
        Page<Product> page = new Page<>(pageNum, PAGESIZE);
        QueryWrapper wrapper = new QueryWrapper();
        Page productPage = productMapper.selectPage(page, wrapper);

        return productPage;
    }

//    @Override
//    public IPage<Product> selectPage(Page<Product> page) {
//        return null;
//    }


}
